package com.xiaodimall.backsys.controller;

import com.xiaodimall.backsys.common.JsonResult;
import com.xiaodimall.backsys.mapper.AdminOrderMapper;
import com.xiaodimall.backsys.pojo.Order;
import com.xiaodimall.backsys.service.AdminOrderService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:
 * @Date: Created in 2022/12/1 17:51
 * @Description:
 */
@RestController
@RequestMapping("/admin/order")
public class AdminOrderController {
    @Resource
    AdminOrderMapper adminOrderMapper;

    @Resource
    AdminOrderService orderService;

    @GetMapping
    public List<Order> getALlOrder(){
        return orderService.getAllOrder();
    }

    @PutMapping
    public JsonResult updateOrderStatus(Integer orderId,Integer status){
        Integer row = adminOrderMapper.updateOrderStatus(orderId,status);
        if (row != 1){
            return new JsonResult(201);
        }
        return new JsonResult(200);
    }

    @PutMapping("/edit")
    public JsonResult updateOrder(Integer orderId, Integer totalPrice, String userAddress){
        return orderService.updateOrder(orderId,totalPrice,userAddress);
    }
}
